package com.abe.mvp.view.activity;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.abe.config.Constants;
import com.abe.mvp.view.activity.base.BaseActivity;
import com.abe.threadmill.R;
import com.abe.utils.NormalUtils;
import com.squareup.picasso.Picasso;

@ContentView(R.layout.activity_exercise_language)
public class ExerciseLanguageActivity extends BaseActivity {
	@ViewInject(R.id.show_exercise_button_back)
	private LinearLayout show_exercise_button_back;
	@ViewInject(R.id.show_exercise_logo)
	private ImageView show_exercise_logo;

	@ViewInject(R.id.tabmenu_layout)
	private ImageView tabmenu_layout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		NormalUtils.setExerciseLanguage();
		initBackground();
		show_exercise_button_back.setVisibility(View.VISIBLE);
		show_exercise_logo.setVisibility(View.VISIBLE);
		gotoActivityForResult(MainMenuActivity.class, 1);
	}

	private void initBackground() {
		/** 菜单页背景 */
		Picasso.with(this).load(R.drawable.run_image_bg_05).centerCrop()
				.placeholder(R.drawable.app_theme_bg).resize(1280, 720)
				.into(tabmenu_layout);
	}
	@Event(value = R.id.show_exercise_button_back, type = View.OnClickListener.class)
	private void back(View view) {
		back();
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (data != null) {
			int extra = data.getIntExtra("extra", Constants.ExitApp);
			if (extra == Constants.SettingLanguage) {
				/** 更新语言后，destroy当前页面，重新绘制 */
				finish();
				Intent it = new Intent(ExerciseLanguageActivity.this,
						ExerciseLanguageActivity.class);
				it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(it);
			} else {
				back();
			}
		} else {
			back();
		}
	}
}
